package com.shuai.baibi.manager;

import com.shuai.baibi.common.ErrorCode;
import com.shuai.baibi.exception.BusinessException;
import com.yupi.yucongming.dev.client.YuCongMingClient;
import com.yupi.yucongming.dev.common.BaseResponse;
import com.yupi.yucongming.dev.model.DevChatRequest;
import com.yupi.yucongming.dev.model.DevChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 调用鱼聪明AI接口并取得返回结果
 */
@Service
public class YuAIManager {
    @Autowired
    private YuCongMingClient yuCongMingClient;

    public String requestAIWithParams(Long id, String askStr) {
        DevChatRequest devChatRequest = new DevChatRequest();
        devChatRequest.setMessage(askStr);
        devChatRequest.setModelId(id);
        BaseResponse<DevChatResponse> responseMessage = yuCongMingClient.doChat(devChatRequest);
        if (responseMessage == null || responseMessage.getData() == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "请求AI接口失败");
        }
        return responseMessage.getData().getContent();
    }
}
